<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>UCStockAdd</title>
</head>
<?PHP
/**
*
* This function used to add a new stock data.
*/
   include ("../../../Connections/SCMS.php");
   include ("../../../Model/CheckClass.php");
   include ("../../../Model/errorReportClass.php");
   include ("../../../Model/databaseOperationClass.php");
   $Check = new CheckClass();
   $errReport = new errorReportClass();
   $databaseOperation = new databaseOperationClass();

 // Get Post value from ../view/StockViewAdd.php
   $name = $_POST['name'];
   $number = $_POST['number'];
   $cost = $_POST['cost'];
   $property = $_POST['property'];
   $stockno = $_POST['stockno'];

 //Set report pass.
$reportTo = '../view/StockViewAdd.php';

 //Check value null.
   if($Check->IsNull($name)){  // If null Report error.
       $errReport->errorReport(3, $reportTo);
       exit;
   }
   else if($Check->IsNull($number)){
       $errReport->errorReport(4, $reportTo);
       exit;
   }
   else if($Check->IsNull($cost)){
       $errReport->errorReport(5, $reportTo);
       exit;
   }
   else if($Check->IsNull($property)){
       $errReport->errorReport(6, $reportTo);
       exit;
   }
   else if($Check->IsNull($stockno)){
       $errReport->errorReport(7, $reportTo);
       exit;
   }
   //Check value number.
  /*else if($Check->notNumber($stockno)){
       $errReport->errorReport(8, $reportTo);
       exit;
   }
   else if($Check->notNumber($number)){
       $errReport->errorReport(9, $reportTo);
       exit;
   }
   else if($Check->notCost($cost)){
       $errReport->errorReport(10, $reportTo);
       exit;
   }
   //Check value is String
   else if($Check->notString($name)){
       $errReport->errorReport(11, $reportTo);
       exit;
   }*/

   $success = $databaseOperation->insertIntoStock($name, $number, $cost, $property, $stockno);

if($success){
      $errReport->errorReport(1, $reportTo);
       exit;
   }
   else{
       $errReport->errorReport(2, $reportTo);
       exit;
   }
?>
<body>
</body>
</html>
